#ifndef _EFFECTS_H_
#define _EFFECTS_H_


#include "Common.h"
#include "String.h"
#include "SharedPtr.h"
#include "Resource.h"
#include "Vector3.h"
#include "EffectModels.h"

class EffectPtr;
class CreatureAIScript;

//物品公共属性
typedef struct effect_common_property
{
	uint32	   start_time;  //特效开始时间	(s)
	uint32	   end_time;	//特效结束时间	(s)
	uint32	   expend_time;	//特效消耗（已用)时间 (ms)

	uint32	   start_ms_time; //开始效果的毫秒时间
	uint32	   end_ms_time;	  //结束的毫秒时间

	int32	data1;
	int32	data2;
	int32	data3;
	int32	data4;
	int32	data5;
	int32	data6;
	int32	data7;
	int32	data8;

	float	fdata1;
	float 	fdata2;
	float	fdata3;
	float	fdata4;

	bool	bdata1;
	bool	bdata2;

	NameValuePairList 	params;

	ResourceProxy		uplink;
	void initialize(void)
	{
		start_time = 0;
		end_time = 0;
		expend_time = 0;

		data1 = 0;
		data2 = 0;
		data3 = 0;
		data4 = 0;
		data5 = 0;
		data6 = 0;
		data7 = 0;
		data8 = 0;
		
		fdata1 = 0;
		fdata2 = 0;
		fdata3 = 0;
		fdata4 = 0;

		bdata1 = false;
		bdata2 = false;

		params.clear();
		
		uplink.setNull();
	}

	effect_common_property()
	{
		initialize();
	}

}effect_common_property_t;

class Effect :public Resource
{
public:
	enum EffectStatus
	{
		EffectStatusNone		= 0,	//无效效果类型
		EffectStatusCreate		= 1,	//特效创建
		EffectStatusProcess		= 2,	//特效处理中
		EffectStatusClose		= 3,	//特效结束
		EffectStatusError		= 4,	//特效处理错误
		EffectStatusDeleted		= 255	//特效数据删除
	};

	enum EffectStyle
	{
		EffectStyleNone			= 0x00,		//无效类型
		EffectStylePlus			= 0x01,		//效果增益
		EffectStyleHarm			= 0x02,		//效果损害
		EffectStyleTrigger		= 0x04,		//效果事件触发
		EffectStyleFixed		= 0x08,		//效果主动影响
		EffectStyleBattle		= 0x10,		//战场效果
		EffectStyleWorld		= 0x20,		//世界效果
		
		EffectStyleBattleTrigger	= EffectStyleTrigger | EffectStyleBattle,	//战场触发效果
		EffectStyleWorldTrigger		= EffectStyleTrigger | EffectStyleWorld		//世界触发效果
	};

	Effect(ResourceManager* creator, const String& name, ResourceHandle handle,
            const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
	~Effect(void);

protected:
       	void prepareImpl(void);
        /** Destroys data cached by prepareImpl.
         */
        void unprepareImpl(void);
        /// @copydoc Resource::loadImpl
        bool loadImpl(void);
        /// @copydoc Resource::postLoadImpl
        void postLoadImpl(void);

	 void preUnloadImpl(void);
        /// @copydoc Resource::unloadImpl
        void unloadImpl(void);
        /// @copydoc Resource::calculateSize
        size_t calculateSize(void) const;

private:
	uint32		m_serial;
	uint32		m_group_id;

	void    initialize(void);
public:

	const uint32  & getSerial() 	{	return m_serial;	}
	const uint32  & getGroup_id()	{	return m_group_id;	}

	const String & getEffectName(void);

	//save item to database	
	bool	SaveDB(void);
	bool	LoadDB(void);
	bool    FetchDB(Field * fields);

	EffectStatus getEffectStatus(void);
	void	setEffectStatus(const EffectStatus & status);

	void	Delete(void);
	void	Destroy(void);


	//物品的模式属性
	EffectModelPtr	model;

	
	//物品公共属性
	effect_common_property_t	common;
};

    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to EffectPtr 
    @note Has to be a subclass since we need operator=.
    We could templatise this instead of repeating per Resource subclass, 
    except to do so requires a form VC6 does not support i.e.
    ResourceSubclassPtr<T> : public SharedPtr<T>
    */
    class SERVER_DECL  EffectPtr : public SharedPtr<Effect>
    {
    public:
        EffectPtr() : SharedPtr<Effect>() {}
        explicit EffectPtr(Effect* rep) : SharedPtr<Effect>(rep) {}
        EffectPtr(const EffectPtr& r) : SharedPtr<Effect>(r) {}
        EffectPtr(const ResourcePtr& r);
        /// Operator used to convert a ResourcePtr to a MeshPtr
        EffectPtr& operator=(const ResourcePtr& r);
    protected:
        /// Override destroy since we need to delete Mesh after fully defined
        void destroy(void);
    };
	

#endif
